package com.example.shop.goods.dto;

import com.example.shop.user.dto.UserBriefInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class Comments {
    //该评论的唯一标识
    protected Long commentsId;
    //评论的用户id
    protected UserBriefInfo commentsUser;
    //评论的内容
    @Field(type = FieldType.Keyword)
    protected String commentsContent;

    @Override
    public String toString() {
        return "Comments{" +
                "commentsId=" + commentsId +
                ", commentsUser=" + commentsUser +
                ", commentsContent='" + commentsContent + '\'' +
                '}';
    }

    /**
     * 响应给前端的评论
     * @param userBriefInfo 用户的简单信息
     * @param comments 评论信息
     * @return 返回响应给前端的评论
     */
    public static Comments getComments(UserBriefInfo userBriefInfo,com.example.shop.pojo.Comments comments){
        Comments commentsView = new Comments();
        commentsView.setCommentsId(comments.getCommentsId());
        commentsView.setCommentsUser(userBriefInfo);
        commentsView.setCommentsContent(comments.getCommentsContent());
        return commentsView;
    }
}
